/*
	Object and membership values.
*/

import java.util.Vector;

class FuzzyObjectSA{

    protected String id;
    protected int last_frame;
    protected int last_x;
    protected int last_y;

    public float last_hd; //horizontal displacement
    public float last_vd; //vertical displacement
    public float last_mov; //last global displacement.

    protected Vector m_values;
    protected Vector<MembershipSA> m_membership;
    protected Vector<RuleMembership> m_rules; 
    protected float normality_degree;
    
    public FuzzyObjectSA(String id){
	    this.id = id;
	    this.last_frame = -1;
	    this.last_x = -1;
	    this.last_y=-1;
	    this.last_hd = 0;
	    this.last_vd = 0;
	    this.last_mov=0;
	    this.normality_degree = 1;
	    this.m_membership = new Vector();
	    this.m_values = new Vector();
	    this.m_rules = new Vector();
    }

    public void updateNormalityDegree(){
	this.normality_degree = 0;
	for(int i=0;i< this.m_rules.size(); i++){
	    RuleMembership rm = this.m_rules.elementAt(i);
	    if(rm.membership_value > this.normality_degree)
		this.normality_degree = rm.membership_value;
	}	
    }
    public float getNormalityDegree(){return this.normality_degree;}
    public Vector<RuleMembership> getMembershipRules(){return this.m_rules;}

    public void erase(){
	m_membership.removeAllElements();
	m_values.removeAllElements();
	m_rules.removeAllElements();
    }
    public void addRuleMembership(RuleMembership rm){
	this.m_rules.addElement(rm);
    }
    
    public int getLastFrame(){
	return this.last_frame;
    }

    public int getLastX(){return this.last_x;}
    public int getLastY(){return this.last_y;}
    public void setLastX(int x){this.last_x = x;}
    public void setLastY(int y){this.last_y = y;}

    public void setValues(Vector values){this.m_values = values;}

    public void setLastFrame(int frame){this.last_frame = frame;}
    public String getId(){return this.id;}
    public Vector getMembershipValues(){return this.m_membership;}
    public Vector getValues(){return this.m_values;}

    public MembershipSA getMembershipByClass(String mclass){
	
	for(int i=0;i< this.m_membership.size();i++){	    
	    MembershipSA m = this.m_membership.elementAt(i);	    	    
	    if((m.getNameClass()).equals(mclass))
		return m;
	}//for
	return null;
    }

    public void addMembership(MembershipSA m){this.m_membership.add(m);}
    
    public String toString(){
	String s=this.id+"\n";
	for(int i=0;i<this.m_membership.size();i++){
	    MembershipSA m = m_membership.elementAt(i);
	    s+=m.getNameClass()+ ":"+ m.getMembershipValue()+"\n";
	}
	return s;
    }
}//end FuzzyObjectSA
